package com.uploadtest.jiaotizhixing;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;
 
public class TransferQueneTest {
    public static void main(String[] args) {
        final char arrayA[] = "1234567".toCharArray();
        final char arrayB[] = "ABCDEFG".toCharArray();
        TransferQueue<Character> transferQueue = new LinkedTransferQueue<>();
        Runnable runnable = () -> {
            for (char charA : arrayA) {
                try {
                    System.out.print(transferQueue.take());
                    transferQueue.transfer(charA);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Runnable runnable1 = () -> {
            for (char charB : arrayB) {
                try {
                    transferQueue.transfer(charB);
                    System.out.print(transferQueue.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        new Thread(runnable).start();
        new Thread(runnable1).start();
    }
}